
package com.ami.kvm.isocaching;

import com.ami.kvm.jviewer.Debug;
import java.io.IOException;
import java.util.LinkedList;

public class RequestHandler extends Thread {
	private boolean running = false;
	private ReadAheadCache readAheadCache = null;
	private boolean sectorMiss = false;
	private long missingStartSector;

	public RequestHandler(ReadAheadCache paramReadAheadCache) {
		this.readAheadCache = paramReadAheadCache;
	}

	public void run() {
     while (this.running) {
       if (isSectorMiss()) {
         byte[] arrayOfByte = new byte[131072];
         long l = this.missingStartSector;
         int i = 64;
         setSectorMiss(false);
         if ((this.readAheadCache.getCacheManager().getFreeBankCount() <= 0) && (this.readAheadCache.getSectorDataCache().size() > 0))
         {
           this.readAheadCache.getCacheManager().setCleanUpCache(true);
           
           synchronized (this.readAheadCache.getCacheLock()) {
             this.readAheadCache.getCacheLock().notifyAll();
             if (this.readAheadCache.isCacheLocked()) {
               try {
                 this.readAheadCache.getCacheLock().wait();
               } catch (InterruptedException localInterruptedException2) {
                 Debug.out.println(localInterruptedException2);
               }
             }
           }
         }
         int tianlin = 0;
         int localObject1 = this.readAheadCache.getCacheManager().getFreeBankCount();
         for (tianlin = 0; tianlin < localObject1; tianlin++)
         {
           try
           {
             if (this.readAheadCache.isFileReadWait()) {
               synchronized (this.readAheadCache.getFileLock()) {
                 try {
                   this.readAheadCache.getFileLock().wait();
                   arrayOfByte = this.readAheadCache.readFromFile(l, i);
                   this.readAheadCache.addToCache(arrayOfByte, l);
                   l += i;
                 } catch (InterruptedException localInterruptedException3) {
                   Debug.out.println(localInterruptedException3);
                 }
               }
             }
           } catch (IOException localIOException) {
             Debug.out.println(localIOException);
             break;
           }
           if (isSectorMiss())
           {
        	   tianlin++;
             break;
           }
         }
         this.readAheadCache.getCacheManager().setFreeBankCount(this.readAheadCache.getCacheManager().getFreeBankCount() - tianlin);
       }
       synchronized (this.readAheadCache.getReqSync()) {
         try {
           this.readAheadCache.getReqSync().wait();
         } catch (InterruptedException localInterruptedException1) {
           Debug.out.println(localInterruptedException1);
         }
       }
     }
   }

	public void startThread() {
		setRunning(true);
		start();
	}

	public void stopThread() {
		setRunning(false);
	}

	public boolean isRunning() {
		return this.running;
	}

	public void setRunning(boolean paramBoolean) {
		this.running = paramBoolean;
	}

	public boolean isSectorMiss() {
		return this.sectorMiss;
	}

	public void setSectorMiss(boolean paramBoolean) {
		this.sectorMiss = paramBoolean;
	}

	public void setMissingBankInfo(long paramLong) {
		this.missingStartSector = paramLong;
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\isocaching\RequestHandler
 * .class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */